package com.anhuanjia.tools.eao.controller;

import java.util.UUID;

import org.springframework.util.StringUtils;

import com.anhuanjia.tools.eao.bean.EaoPublicityURL;
import com.efastsoft.framework.UIFacade;
import com.efastsoft.framework.annotation.Alias;
import com.efastsoft.framework.annotation.Priv;
import com.efastsoft.framework.annotation.Priv.LoginType;
import com.efastsoft.framework.data.DataRow;
import com.efastsoft.framework.data.DataTable;
import com.efastsoft.framework.data.Q;
import com.efastsoft.framework.data.Transaction;

/**
 * 公示网址表操作类
 * 
 * @author Administrator
 *
 */
@Alias(value = "publicityURL")
public class PublicityURLUI extends UIFacade {

	/**
	 * 增加或更改
	 */
	@Priv(loginType = LoginType.Member)
	public void saveOrUpdate() {
		
		Transaction transaction = new Transaction();
		EaoPublicityURL publicityURL = new EaoPublicityURL();
		publicityURL.setValue(this.Request);
		String id = publicityURL.getPublicityId();
		if (StringUtils.isEmpty(id)) {
			// 添加
			publicityURL.setPublicityId(UUID.randomUUID().toString());
			transaction.insert(publicityURL);
			transaction.commit();
			if (transaction.commit()) {
				s("添加成功");
			} else {
				f("添加失败");
			}
		} else {
			// 更新
			DataTable dt = new Q(" select * from eao_publicity_url where PublicityId = ?", id).fetch();
			EaoPublicityURL entity = new EaoPublicityURL();
			entity.setValue(dt.get(0));
			entity.setValue(this.Request);
			transaction.update(entity);
			transaction.commit();
			if (transaction.commit()) {
				s("更新成功");
			} else {
				f("更新失败");
			}
		}
	}

	/**
	 * 根据项目ID查询其下的专家技术评估意见
	 */
	@Priv(loginType = LoginType.Member)
	public void findByProjectId() {
		String pid = $V("Id");
		if (StringUtils.isEmpty(pid)) {
			f("查询失败，请确认查询信息");
			return;
		}
		DataTable dt = new Q("select * from eao_publicity_questions where PublicityId = ? ", pid).fetch();
		if (dt.getRowCount() > 0) {
			for (DataRow dr : dt) {
				EaoPublicityURL entity = new EaoPublicityURL();
				entity.setValue(dr);
				this.Response.put("PublicityURL", entity);
			}
		}
	}
}
